class Solution
{
public:
    int rearrangeCharacters(string s, string target)
    {
        unordered_map<char, int> sCount;
        unordered_map<char, int> tCount;
        for (char c : s)
        {
            ++sCount[c];
        }
        for (char t : target)
        {
            ++tCount[t];
        }
        int result = INT_MAX;
        for (char t : target)
        {
            result = min(result, sCount[t] / tCount[t]);
        }
        return result;
    }
};